﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Math.Algebra.UnitTests.MatrixTests.DoubleTests
{
    [TestClass]
    public class DivideTests : DoubleTestBase
    {
        [TestMethod, ExpectedException(typeof(InvalidOperationException))]
        public void Divide_throws_an_InvalidOperationException_when_the_numerator_is_null()
        {
            var matrix1 = Matrix;

            matrix1.Divide(null);
        }

        [TestMethod]
        public void Divide_returns_null_when_the_matrix_is_null()
        {
            const double factor = 2;

            var result = Matrix<double>.Divide(null, factor);
            Assert.IsNull(result);
        }

        [TestMethod]
        public void Divide_performs_a_division_on_each_element()
        {
            /* Matrix 1
                    1   2   3 
                    ----------
                1 | 2   4   6 
                2 | 4   8   12
                3 | 6   12  18
            */

            const int m = 3;
            var matrix1 = CreateMatrix(m, m, (i, j) => (i + 1) * (j + 1) * 2);
            const double factor = 2;

            matrix1.Divide(factor);

            for (var i = 0; i < m; i++)
            {
                for (var j = 0; j < m; j++)
                {
                    Assert.AreEqual((i + 1) * (j + 1), matrix1[i, j].Value);
                }
            }
        }
    }
}